import http from "@/api/http";

const BASE_URL = "/ai";

const AI_MODEL_BASE_URL = `${BASE_URL}/model`;

const AI_APPLICATION_BASE_URL = `${BASE_URL}/application`;

const AI_CHAT_BASE_URL = `${BASE_URL}/chat`;

const AI_CHAT_SESSION_BASE_URL = `${BASE_URL}/chat/session`;

export default {
  // 模型相关-start
  fetchModelList() {
    return http.get(AI_MODEL_BASE_URL + "/list");
  },
  getModelDetail(id) {
    return http.get(`${AI_MODEL_BASE_URL}/${id}`);
  },
  createModel(data) {
    return http.post(AI_MODEL_BASE_URL, data);
  },
  updateModel(data) {
    return http.put(AI_MODEL_BASE_URL, data);
  },
  deleteModel(id) {
    return http.delete(`${AI_MODEL_BASE_URL}/${id}`);
  },
  // 模型相关-end

  // Application相关-start

  // 获取Application列表
  fetchApplicationList() {
    return http.get(`${AI_APPLICATION_BASE_URL}/list`);
  },

  // 获取Application详情
  getApplicationDetail(id) {
    return http.get(`${AI_APPLICATION_BASE_URL}/${id}`);
  },

  // 创建Application
  createApplication(data) {
    return http.post(`${AI_APPLICATION_BASE_URL}`, data);
  },

  // 更新Application
  updateApplication(data) {
    return http.put(`${AI_APPLICATION_BASE_URL}`, data);
  },

  // 删除Application
  deleteApplication(id) {
    return http.delete(`${AI_APPLICATION_BASE_URL}/${id}`);
  },
  // Application相关-end

  // chat-start
  getChatSessionList(applicationId) {
    return http.get(`${AI_CHAT_SESSION_BASE_URL}/list`, {
      params: { applicationId },
    });
  },
  getChatSessionMessageList(sessionId) {
    return http.get(`${AI_CHAT_SESSION_BASE_URL}/messages`, {
      params: { sessionId },
    });
  },
  deleteChatSession(sessionId) {
    return http.delete(`${AI_CHAT_SESSION_BASE_URL}/${sessionId}`);
  },
  deleteChatSessions(sessionIds) {
    return http.post(`${AI_CHAT_SESSION_BASE_URL}/batch`, [...sessionIds]);
  },
  partialUpdateChatSession({ sessionId, property, value }) {
    return http.put(`${AI_CHAT_SESSION_BASE_URL}/partialUpdate`, {
      sessionId,
      property,
      value,
    });
  },

  // chat-end
};
